﻿Imports System.Text

Public Class NewUser

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim entryError As Boolean = False

        For Each _ctrl As Control In Me.grpbxNewUserInfo.Controls
            If _ctrl.GetType = GetType(TextBox) Then
                If _ctrl.Text = "" Then
                    entryError = True
                    Exit For
                End If
            End If
        Next

        If entryError Then
            MessageBox.Show("All fields are required. Please finish completing the form and then try again.", "EZ Ticket - Input Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else
            Dim new_user As New clsUser(Me.txtUserName.Text, Me.txtUserEmail.Text, Me.txtFirstName.Text, Me.txtLastName.Text, Me.txtPassword.Text, Me.chkIsTech.Checked)
            MessageBox.Show("User successfully created.", "EZ Ticket - New User Created", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.Close()
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        ' Closes the New User form

        Me.Close()
    End Sub

    Private Sub Password_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPassword.TextChanged, txtRetypePassword.TextChanged
        If Me.txtPassword.Text <> Me.txtRetypePassword.Text Then
            Me.btnSave.Enabled = False
            Me.lblPasswordMessage.Visible = True
        Else
            Me.btnSave.Enabled = True
            Me.lblPasswordMessage.Visible = False
        End If
    End Sub
End Class